import { createSlice } from "@reduxjs/toolkit";

//创建 slice 对象
let zanSlice = createSlice({
  //别名
  name: 'zan',
  //初始值  initial 初始化  state 状态
  initialState: {value: 20},
  //设置 reducer 功能
  reducers: {
    incre: (state, action) => {
      state.value += action.payload;
    },
    decre: (state, action) => {
      state.value -= action.payload;
    }
  }
});

//获得 slice 的 reducer 函数
let zanReducer = zanSlice.reducer;

//获得 action creator
export let {incre, decre} = zanSlice.actions;

//暴露 reducer
export default zanReducer;